package com.mifan.controller;/*
 * @Author Milan
 * @Date 2024/9/25 21:17
 */

import com.mifan.common.Results;
import com.mifan.mapper.RoleMenuMapper;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/roleMenu")
public class RoleMenuController {
    @Resource
    RoleMenuMapper roleMenuMapper;

    @PostMapping("/assignMenusToRole")
    public Results assignMenusToRole(@RequestParam Long roleId, @RequestBody List<Long> menuIds) {
        if(menuIds == null || menuIds.size() == 0) {
            return Results.success("清除所有菜单");
        }
        int oldRoleMenus = roleMenuMapper.deleteOldRoleMenus(roleId, menuIds);
        int inserted = roleMenuMapper.insertRoleMenus(roleId, menuIds);
        return Results.success(null);
    }
}
